package com.jeff.tianti.controller.channel;

import com.jeff.tianti.cms.dto.font.AwardsToDeclareTo;
import com.jeff.tianti.cms.dto.font.PageBeanUid;
import com.jeff.tianti.cms.entity.AwardsToDeclare;
import com.jeff.tianti.cms.service.AwardsToDeclareService;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.BaseEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/channel/awards")//江苏频道_奖项申报模块
@CrossOrigin(maxAge = 3600)
public class AwardsToDeclareController {
    @Autowired
    private AwardsToDeclareService awardsToDeclareService;

    /**
     * @Ceator:liuYI
     * @Describe:奖项申报-用户在线申请
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public AjaxResult save(@RequestBody AwardsToDeclare awardsToDeclare) {
        String uid = awardsToDeclare.getUid();
        if (StringUtils.isBlank(uid)) {
            throw new RuntimeException("uid:参数缺失");
        }
        AwardsToDeclareTo awardsToDeclareTo = new AwardsToDeclareTo();
        awardsToDeclareTo.setUid(awardsToDeclare.getUid());
        awardsToDeclareTo.setState(awardsToDeclare.getState());
        List<AwardsToDeclare> list = awardsToDeclareService.findByUidAndState(awardsToDeclareTo);
        if (list == null || list.size() <= 0) {
            awardsToDeclare.setAuditFlag(BaseEntity.AUDIT_FLAG_NOT);
            awardsToDeclareService.save(awardsToDeclare);
            return AjaxResult.setSuccessData(null);
        }
        throw new RuntimeException("奖项申报一个用户只有一次机会");
    }

    /**
     * @Ceator:liuYI
     * @Describe:奖项申报-用户在线申请-一个用户只能一次申请
     */
    @RequestMapping(value = "/isAwardsToDeclare", method = RequestMethod.POST)
    public AjaxResult isAwardsToDeclare(@RequestBody AwardsToDeclareTo awardsToDeclareTo) {
        List<AwardsToDeclare> list = awardsToDeclareService.findByUidAndState(awardsToDeclareTo);
        if (list == null || list.size() <= 0) {
            return AjaxResult.setSuccessData(null);
        }
        throw new RuntimeException("用户已提交奖项申报信息");
    }
}
